var util = require("../../../utils/util.js"),
    {api} = require("../../../utils/api.js"),
    app = getApp();
Page({

    /**
     * 页面的初始数据
     */
    data: {
        storeId: '',
        detail: null,
        markers: [],
        lineIndex:1
    },
    /**
     * 生命周期函数--监听页面加载
     */
    onLoad(options) {
        this.setData({
            storeId: options.id
        });
        this.getStoreDetail()
    },
    async getStoreDetail() {
        let {
            data
        } = await api.getStoreDetail({
            store_id: this.data.storeId,
            latitude: wx.getStorageSync('latitude'),
            longitude: wx.getStorageSync('longitude'),
        });
        
        if(data && data.store){
            data.store.torebus_route=util.regularConfig.isString(data.store.torebus_route)?data.store.torebus_route:'';
            data.store.metro_route=util.regularConfig.isString(data.store.metro_route)?data.store.metro_route:'';
            data.store.rent_route=util.regularConfig.isString(data.store.rent_route)?data.store.rent_route:'';
            data.store.plane_route=util.regularConfig.isString(data.store.plane_route)?data.store.plane_route:'';
        }
        this.setData({ 
            detail: data && data.store ? data.store : null
        })
        if (data.store) {
            wx.setNavigationBarTitle({
                title: data.name,
            })
            let markers = [{
                id: 1,
                latitude: data.store.lat,
                longitude: data.store.lng,
                iconPath: 'https://test.okall.com.cn/h5/hecardstatic/static/indexImgs/location-red-icon.png',
                width: 25,
                height: 25,
                address: data.store.address,
                callout: {
                    display: 'ALWAYS',
                    content: data.store.name,
                    fontSize: 12,
                    padding: 10
                }
            }];
            this.setData({
                markers
            })
        }
    },
    toMapNav() {
        let d = this.data.detail;
        wx.openLocation({
            latitude: parseFloat(d.lat),
            longitude: parseFloat(d.lng),
            scale: 18,
            name: d.name,
            address: d.address
        });
    },
    makePhoneCall(t) {
        let d = this.data.detail;
        wx.makePhoneCall({
            phoneNumber: d.contact_phone
        }).catch(function () {});
    },
    lineClick(e){
        this.setData({lineIndex:e.currentTarget.dataset.id})
    },
    /**
     * 生命周期函数--监听页面初次渲染完成
     */
    onReady() {

    },

    /**
     * 生命周期函数--监听页面显示
     */
    onShow() {

    },

    /**
     * 生命周期函数--监听页面隐藏
     */
    onHide() {

    },

    /**
     * 生命周期函数--监听页面卸载
     */
    onUnload() {

    },

    /**
     * 页面相关事件处理函数--监听用户下拉动作
     */
    onPullDownRefresh() {

    },

    /**
     * 页面上拉触底事件的处理函数
     */
    onReachBottom() {

    },

    /**
     * 用户点击右上角分享
     */
    onShareAppMessage(e) {
        return util.shareEvent(e)
      }
})